<%@page contentType="text/html; charset=utf-8" %>
<%@ include file="/commons/taglibs.jsp"%>
<%@ taglib uri="http://www.myce.net.cn/ce-tag" prefix="ce"%>
<%@ taglib uri="/WEB-INF/tld/pms-tag.tld" prefix="mypms" %>
<%@ include file="/commons/commonEdit.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>登记来访人员&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</title>
<link href="${ctx}/scripts/jscalendar-1.0/calendar-blue.css" rel="stylesheet" type="text/css">
<script language="JavaScript"  src="${ctx}/scripts/jscalendar-1.0/calendar.js"></script>
<script language="JavaScript"  src="${ctx}/scripts/jscalendar-1.0/lang/calendar-en.js"></script>
<script language="JavaScript"  src="${ctx}/scripts/jscalendar-1.0/calendar-setup.js"></script>
<script language="JavaScript"  src="${ctx}/scripts/common/prototype.js"></script>
<script language="JavaScript"  src="${ctx}/scripts/div/common.js"></script>

<script type="text/javascript" src="${ctx}/scripts/validation/validation.js"></script>

<script>
//定义一个全局的URL
var ACTION_URL="${ctx}/customer_callInPersonAction.do?";
//存放控件的原始值
var sourceValue="";

function next(url){
	window.location.href = url;
}

//检测控件的文本是否修改,修改返回true,否则返回false
function checkChangeValue(o){
	var oldValue=o.getAttribute('oldValue');
	if(oldValue==o.value){
		return false;
	}else{
		o.setAttribute('oldValue',o.value);
		return true;
	}
}

//开始查询证件
function queryParticipant(o){
	if(!checkChangeValue(o)) return;
	var url=　ACTION_URL　+　"method=queryParticipant";
	var pars = "certificateType="　+ $F('certificateType') + "&certificateNo=" + $F('certificateNo');
	var myAjax = new Ajax.Request(
                    url,
                    {method: 'post', parameters: pars, onComplete: showResponse}
                    );
}
//证件查询响应结果
function showResponse(result){
	var obj=eval('(' + result.responseText + ')');
	if(result.responseText != 'false'){
		var isTrue=confirm("该证件信息已经存在是否载入？")
		if(isTrue){
			writeResult(obj);
		}else{
			$('certificateNo').value="";
			$('certificateNo').focus();
		}
	}
}
//将返回的数据填充至相应框中
function writeResult(obj){
	$('participantName').value=obj.participantName;
	$('appellative').value=obj.appellative;
	$('telephone').value=obj.telephone;
	var sex=document.getElementsByName("sex");
	for(var i=0;i<sex.length;i++){
		if(sex[i].value==obj.sex){
			sex[i].checked=true;
		}
	}
}

//增加操作
function addCallInPerson(){
	saveCallInPerson("showResponseAdd");
}

//增加并新增操作
function addAgainCallInPerson(){
	saveCallInPerson("showResponseAddAgain");
}

//保存操作,参数为响应结果的方法
function saveCallInPerson(fname){
	var url= ACTION_URL + "method=addCallInPerson";
	var pars=$('fCallInPerson').serialize();
	//校验
	var isTure=$("fCallInPerson").fireEvent("onSubmit")
	//ajax提交
	if(isTure){
		closeORopenButton();
		var myAjax = new Ajax.Request(
	                    url,
	                    {method: 'post', parameters: pars, onComplete: eval(fname)}
	                    );
	}
}
//增加操作的响应
function showResponseAdd(result){
	var obj=findFrame('callInPersonList');
	obj.parent.reLoadIFrameList();
	closeORopenButton();
	windowClose();
}

//增加并新增操作的响应
function showResponseAddAgain(result){
	var obj=findFrame('callInPersonList');
	obj.parent.reLoadIFrameList();
	closeORopenButton();
	location.reload();
}

//单选房间
function chooseSingleHouse(){
	var url="${ctx}/customer_chooseSingleHouseAction.do?method=chooseBuildingMain";
	//window.showModalDialog(url,window,'dialogWidth:650px;dialogHeight:500px;help:no;status:no;scroll:no;certer');
	top.windowOpen(url, 'singlehouse', '选择房间信息',500,650);
}

//设置房号信息
function setHouseInfo(houseId,houseNum){
	$('address').value=houseNum;
}

//关闭或打开按钮事件
function closeORopenButton(){
	$('window_footer').disabled= !$('window_footer').disabled;
	$('btn1_42').disabled= !$('btn1_42').disabled;
	$('btn1_22').disabled= !$('btn1_22').disabled;
	$('btn1_32').disabled= !$('btn1_32').disabled;
}

//初始化
function init(){
	$('participantName').focus();
	sourceValue=$('fCallInPerson').serialize();
}

function closeWin(){
	var newValue=$('fCallInPerson').serialize();
	if(sourceValue==newValue){
		windowClose();
	}else{
		var result=confirm("是否要保存并退出？");
		if(result){
			addCallInPerson();
			return;
		}else{
			windowClose();
		}
	}
}
</script>
</head>

<body onload="init()">
<form action="" name="fCallInPerson" method="post" class="required-validate">
<input type="hidden" id="currentDate" value="${currentDate}">
<input type="submit" id="submitForm" style="display: none;">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td class="window_head_outBg"><table border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td><img src="${ctx}/images/ico_Advance.gif" width="16" height="16" align="absmiddle"> <span class="window_head_intext">登记来访人员</span></td>
        </tr>

    </table></td>
  </tr>
  <tr>
    <td class="aux_header_line_1"></td>
  </tr>
  <tr>
    <td class="aux_header_line_2"></td>
  </tr>
  <tr>

    <td valign="middle" class="content"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="container_in_show">
      <tr>
        <td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" id="tab_subMenu1">
            <tr>
              <td><table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">
                  <tr>
                    <td><table width="100%" border="0" cellpadding="0" cellspacing="1" class="aux_intable_color">

                        <tr>
                          <td class="aux_intable_td1">姓名：</td>

                          <td class="aux_intable_require"><input id="participantName" name="participantName" type="text" class="inputtext required validate-char" size="16" maxlength="80" tabindex="1">                          </td>
                          </tr>

                        <tr>
                          <td class="aux_intable_td1">性别：</td>
                          <td class="aux_intable_require">
                         	 <mypms:Radio name="sex" code="CS_INDIVIDUAL_SEX" id="sex" className="validate-one-required " tabIndex="2"></mypms:Radio>
                         </td>

                          </tr>
                        <tr>
                          <td class="aux_intable_td1">证件类型：</td>
                          <td class="aux_intable_td2">
                          	<ce:unitedSelect
                          	dataList="${certificateList}"
                          	id="certificateType"
                          	name="certificateType"
                          	optionLabel="idTypeName"
                          	optionValue="idTypeId"
                          	selectText="请选择..."
                          	onChange="queryParticipant(this);"
                          	tabIndex="3"
                          	>
                          	</ce:unitedSelect>

                         </td>
                        </tr>

                        <tr>
                          <td class="aux_intable_td1">证件号码：</td>
                          <td class="aux_intable_td2"><input id="certificateNo" name="certificateNo" type="text" class="inputtext validate-char" size="16" onblur="queryParticipant(this);" tabindex="4" maxlength="36">                          </td>
                        </tr>

                        <tr>
                          <td class="aux_intable_td1">称呼：</td>
                          <td class="aux_intable_td2">

                            <input id="appellative" name="appellative" type="text" class="inputtext validate-char" size="16" tabindex="5" maxlength="20">                          </td>
                        </tr>
                        <tr>
                          <td class="aux_intable_td1">联系电话：</td>
                          <td class="aux_intable_td2">
                            <input id="telephone" name="telephone" type="text" class="inputtext validate-char" size="16" tabindex="6" maxlength="80">                          </td>
                        </tr>

                        <tr>
                          <td class="aux_intable_td1">来访地址：</td>
                          <td class="aux_intable_require"><table border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td><input name="address" type="text" class="inputtext required validate-char" size="16" tabindex="7" maxlength="100" afterInsert="sselectHouse"></td>
                              <td width="4">&nbsp;</td>
                              <td><a href="#"  onClick="chooseSingleHouse();" onFocus="this.blur()"><img src="${ctx}/images/ico_houesno.GIF" alt="请点选查找房号" border="0"></a> <span id="sselectHouse"></span> </td>
                            </tr>

                          </table></td>
                        </tr>
                        <tr>
                          <td class="aux_intable_td1">被访问者姓名：</td>
                          <td class="aux_intable_td2">
                            <input name="interviewee" type="text" class="inputtext validate-char" size="16" tabindex="8" maxlength="30">                          </td>
                        </tr>

                        <tr>

                          <td class="aux_intable_td1">来访时间：</td>
                          <td class="aux_intable_require"><table border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td><input id="commingTime" name="commingTime" type="text" class="inputtext required validate-dateTime-yyyy-mm-dd-HH:mm less-equals-than-currentDate" validateMessage="来访时间必须小于或等于当前服务器时间" value="${currentDate}" size="16" tabindex="9" afterInsert="sselectcdate"></td>
                              <td width="4">&nbsp;</td>
                              <td><a href="#" ><img id="commingTimeButton" src="${ctx}/images/ico_clock.gif" alt="请点选查找日期" border="0"></a> <span id="sselectcdate"></span> </td>
                            </tr>
                          </table></td>

                        </tr>
                        <tr>
                          <td class="aux_intable_td1">离开时间：</td>
                          <td class="aux_intable_td2"><table border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td><input name="goingTime" type="text" class="inputtext validate-dateTime-yyyy-mm-dd-HH:mm great-than-commingTime less-equals-than-currentDate" validateMessage="离开时间必须小于或等于当前服务器时间且大于来访时间"  size="16" tabindex="10" afterInsert="sselectgdate"></td>
                              <td width="4">&nbsp;</td>
                              <td><a href="#"><img id="goingTimeButton" src="${ctx}/images/ico_clock.gif" alt="请点选查找日期" border="0"></a> <span id="sselectgdate"></span> </td>

                            </tr>
                          </table></td>
                        </tr>
                        <tr>
                          <td valign="top" class="aux_intable_td1">来访事由：</td>
                          <td valign="top" class="aux_intable_require_more"><textarea name="causation" cols="20" rows="3" class="textareatext required max-length-1000" tabindex="11"></textarea></td>
                          </tr>
                    </table></td>

                  </tr>
              </table></td>
            </tr>
        </table></td>
      </tr>
    </table>
    </td>
  </tr>

  <tr>
    <td class="window_footer" id="window_footer"><table border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><table border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td class="buttonOffLeft" id="btn1_41"></td>
              <td class="buttonOffMiddle" id="btn1_42" tabIndex="12" onClick="addAgainCallInPerson();" onMouseOver="btn_change_over(4)" onMouseOut="btn_change_out(4)" onblur="btn_change(4)"><img src="${ctx}/images/ico_htn_interim.gif" alt="" width="14" height="15" border="0" align="absbottom">&nbsp;保存并新增</td>
              <td class="buttonOffRight" id="btn1_43"></td>

            </tr>
        </table></td>
        <td class="btn_between_four"></td>
        <td><table border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td class="buttonOffLeft" id="btn1_21"></td>
              <td class="buttonOffMiddle"  tabIndex="13" id="btn1_22" onClick="addCallInPerson();" onMouseOver="btn_change_over(2)" onMouseOut="btn_change_out(2)" onblur="btn_change(2)"><img src="${ctx}/images/ico_ok.gif" alt="" width="14" height="14" border="0" align="absbottom" >保存</td>
              <td class="buttonOffRight" id="btn1_23"></td>

            </tr>
        </table></td>
        <td class="btn_between_space"></td>
        <td><table border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td class="buttonOffLeft" id="btn1_31"></td>
              <td class="buttonOffMiddle" tabIndex="14" id="btn1_32" onClick="closeWin();" onMouseOver="btn_change_over(3)" onMouseOut="btn_change_out(3)" onblur="btn_change(3)"><img src="${ctx}/images/ico_cancel.gif" alt="" width="14" height="14" border="0" align="absbottom">关闭</td>
              <td class="buttonOffRight" id="btn1_33"></td>

            </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
</form>
<script type="text/javascript">
              Calendar.setup(
              {
	              inputField : "commingTime", // ID of the input field
	              ifFormat : "%Y-%m-%d %H:%M", // the date format
	              button : "commingTimeButton", // ID of the button
	              align          :    "Tl",           // alignment (defaults to "Bl")
			      singleClick    :    true,
			      showsTime		 :	  true
              }
              );

              Calendar.setup(
              {
	              inputField : "goingTime", // ID of the input field
	              ifFormat : "%Y-%m-%d %H:%M", // the date format
	              button : "goingTimeButton", // ID of the button
	              align          :    "Tl",           // alignment (defaults to "Bl")
			      singleClick    :    true,
			      showsTime		 :	  true
              }
              );

</script>
</body>
</html>